package com.cs171.market.controller;

import com.alibaba.fastjson.JSONObject;
import com.cs171.market.Repository.OrderRepository;
import com.cs171.market.entity.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yangyifei
 * @version 1.0
 * @date 2020/6/21 22:32
 */

@CrossOrigin
@RestController
public class PayController {
    @Autowired
    private OrderRepository orderRepository;

    @PostMapping("pay")
    //更改订单状态
    public Object getFee(@RequestBody JSONObject jsonParam){
        String act = jsonParam.getString("action");
        Integer id = jsonParam.getInteger("id");

        JSONObject result = new JSONObject();
        Order order = orderRepository.findById(id).orElse(null);
        if(order != null){
            order.setOpay(1);
            order.setOsend("运输中");
            result.put("code",200);
            return result;
        }
        result.put("error", "可能是数据库暂时连接不上或无此订单号，请稍后再试");
        result.put("code",500);
        return result;
    }

//    public static void main(String[] args) {
//        Integer s = (int) System.currentTimeMillis()/1000;
//        System.out.println(s);
//    }
}
